import * as types from './types'

export default {
    [types.UPDATE_LOGINNAME](state, payload) {
        state.loginName = payload.loginName
    },
    [types.UPDATE_LOGINPASSWORD](state, payload) {
        state.loginPassWord = payload.loginPassWord
    },
    [types.UPDATE_SK](state, payload) {
        state.token = payload.sk
    },
    [types.UPDATE_USERINFO](state, payload) {
        state.userInfo = payload.userinfo
    },
    [types.TOUCHMOVE](state, event) {
        var startY = event.clientY || event.touches[0].clientY
        var startTop = state.divContentTop,
            defHeight = parseInt(startTop.indexOf('%') >= 0 ? ((parseFloat(startTop) / 100) * (window.innerHeight ? window.innerHeight : document.documentElement.clientHeight)) : startTop),
            minHeight = ((parseFloat(state.divContentMinTop) / 100) * (window.innerHeight ? window.innerHeight : document.documentElement.clientHeight)),
            sliderHeight = (window.innerHeight ? window.innerHeight : document.documentElement.clientHeight) * 0.03
        $(document).on('touchmove mousemove', function (e) {
            var endY = e.clientY || e.originalEvent.targetTouches[0].clientY
            var dy = endY - startY
            state.divContentTop = dy + defHeight + 'px';
            if (parseInt(state.divContentTop) <= minHeight) {
                state.divContentTop = minHeight + 'px'
            }
            if (parseInt(state.divContentTop) > parseFloat($('.divContent').height()) - sliderHeight) {
                state.divContentTop = parseFloat($('.divContent').height()) - sliderHeight + 'px'
            }
        })
        event.preventDefault()
        $(document).on('touchend mouseup', function () {
            $(document).unbind()
        })
    },
    [types.UPDATE_CONFIG](state, payload) {
        state.config = payload.config
    }
}